package com.lc.midi.script;


import com.lc.midi.keyEvent.KeyEvents;

public interface IScript {
	String createScript(KeyEvents keyEvents, Config config);
	
	public static IScript getIScript(Config config) {
		switch (config.getKind()) {
		case "js":
			return new JsScript();
		case "leidian":
			return new LeidianScript();
		default:
			break;
		}
		return null;
	}
	
	public static int getKeyPosX(int keyId, Config config) {
		final double[] k = new double[] {0.5, 1, 1.5, 2, 2.5, 3.5, 4, 4.5, 5, 5.5, 6, 6.5};
		int left = (keyId / 12 - 2) * 7 + 2;
		return (int)(config.getWidth() / 52.0 * (left + k[keyId%12]));
	}
	public static int getKeyPosY(int keyId, Config config) {
		int y = config.getHeight();
		int y1 = y / 16;
		int y2 = y1 * 3;
		if ("完美钢琴".equals(config.getPianoApp())) {
			y2 = y1 * 8;
		}
		y1 = y - y1;
		y2 = y - y2;
		if (isBlackKey(keyId)) {
			return y2;
		}else {
			return y1;
		}
	}
	public static boolean isBlackKey(int keyId) {
		final boolean[] k = new boolean[] {false, true, false, true, false, 
				false, true, false, true, false, true, false};
		return k[keyId%12];
	}
	public static String getKeyName(int keyId) {
		final String[] k = new String[]{"1", "1#", "2", "2#", "3",
				"4", "4#", "5", "5#", "6", "6#", "7"};
		String s = "";
		int d = keyId / 12 - 5;
		for (int i = 0; i > d; i--) {
			s += "-";
		}
		for (int i = 0; i < d; i++) {
			s += "+";
		}
		s += k[keyId%12];
		return s;
	}
}
